package com.jisf.driver.controller;

import com.jisf.driver.entity.po.Course;
import com.jisf.driver.entity.vo.CourseCoachVo;
import com.jisf.driver.entity.vo.CourseListVo;
import com.jisf.driver.entity.vo.StudentCourseVo;
import com.jisf.driver.response.Result;
import com.jisf.driver.response.ResultCode;
import com.jisf.driver.service.ICourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jisf
 * @since 2022-05-06
 */
@RestController
@RequestMapping("/driver/course")
public class CourseController {

    @Autowired
    private ICourseService iCourseService;

    @PostMapping("student/course")
    @PreAuthorize("hasAnyAuthority('course:student:course')")
    public Result<?> getStudentCourse(){
        List<StudentCourseVo> studentCourse = iCourseService.getStudentCourse();
        return Result.ok(studentCourse);
    }

    @GetMapping("course/coach")
    @PreAuthorize("hasAnyAuthority('course:course:coach')")
    public Result<?> getCourseCoach(@RequestParam Integer coachId){
        CourseCoachVo courseCoach = iCourseService.getCourseCoach(coachId);
        return Result.ok(courseCoach);
    }

    @GetMapping("delete")
    @PreAuthorize("hasAnyAuthority('course:delete')")
    public Result<?> cancelCourse(@RequestParam Integer id){
        ResultCode resultCode = iCourseService.cancelCourse(id);
        return Result.ok(resultCode);
    }

    @GetMapping("appoint/date")
    @PreAuthorize("hasAnyAuthority('course:appoint:date')")
    public Result<?> getCourseAppointDate(){
        List<String> courseAppointDate = iCourseService.getCourseAppointDate();
        return Result.ok(courseAppointDate);
    }

    @GetMapping("coach/course")
    @PreAuthorize("hasAnyAuthority('course:coach:course')")
    public Result<?> getCoachCourse(@RequestParam Integer id, @RequestParam String date){
        List<Course> coachCourse = iCourseService.getCoachCourse(id, date);
        return Result.ok(coachCourse);
    }

    @PostMapping("appoint/course")
    @PreAuthorize("hasAnyAuthority('course:appoint:course')")
    public Result<?> appointCourse(@RequestBody Course course){
        ResultCode resultCode = iCourseService.appointCourse(course);
        return Result.ok(resultCode);
    }

    @GetMapping("coach/selfCourse")
    @PreAuthorize("hasAnyAuthority('course:coach:selfCourse')")
    public Result<?> getCoachCourse(@RequestParam String date){
        List<CourseListVo> coachCourse = iCourseService.getCoachCourse(date);
        return Result.ok(coachCourse);
    }

    @GetMapping("update/date")
    @PreAuthorize("hasAnyAuthority('course:update:date')")
    public Result<?> getCourseUpdateDate(){
        List<String> courseAppointDate = iCourseService.getCourseUpdateDate();
        return Result.ok(courseAppointDate);
    }

    @PostMapping("close/appoint")
    @PreAuthorize("hasAnyAuthority('course:close:appoint')")
    public Result<?> closeAppoint(@RequestBody CourseListVo courseListVo){
        ResultCode resultCode = iCourseService.closeAppoint(courseListVo);
        return Result.ok(resultCode);
    }

    @PostMapping("open/appoint")
    @PreAuthorize("hasAnyAuthority('course:open:appoint')")
    public Result<?> openAppoint(@RequestBody CourseListVo courseListVo){
        ResultCode resultCode = iCourseService.openAppoint(courseListVo);
        return Result.ok(resultCode);
    }

}
